﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using Quick_Sort;

namespace Gui
{
    public class QuickSortCommandOption : MenuItem
    {
        public QuickSortCommandOption(string MenuText)
            : base(MenuText)
        {

        }

        public override void Execute()
        {

            Console.Write("size of array: ");

            int size = Convert.ToInt32(Console.ReadLine());
            Console.Write("Paralell tree limit: ");
            int limit = Convert.ToInt32(Console.ReadLine());
            Console.Write("Max possible number: ");
            int max = Convert.ToInt32(Console.ReadLine());
            Stopwatch sw = new Stopwatch();
            


            int[] array = MethodLibrary.GenerateArray(1, max, size);
            Console.WriteLine("array created, starting sort");
            QuickSort q = new QuickSort(array,limit);
            sw.Start();
            q.SequentialSort();
            sw.Stop();
            if(size<1001)
            for (int i = 0; i < array.Length; i++)
            {
                Console.Write(q.IntArray[i] + ", ");
            }
            int j = 0;
            for (int i = 1; i < array.Length; i++)
            {
                if (q.IntArray[i] < q.IntArray[j])
                    Console.WriteLine("something's not right arr[{0}]: {1} arr[{2}]: {3}", j, q.IntArray[j], i, q.IntArray[i]);
                j++;
                

            }
            Console.WriteLine("\nTime taken in Sequential:" + (double)sw.ElapsedMilliseconds / 1000);

           
            
           /*
           
            Stopwatch sw = new Stopwatch();
            sw.Start();


            int[] array = MethodLibrary.GenerateArray(1, 500, 1000);
            QuickSort q = new QuickSort(array, 1);
            q.ParallelSort();

            for (int i = 1; i < array.Length; i++)
            {
                Console.Write(q.IntArray[i] + ", ");
            }
            Console.WriteLine("\nTime taken in Parallel:" + (double)sw.ElapsedMilliseconds / 1000);
            
           */
            
        }
        }

        
    }

